import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:hxdj/common/base_page/base_page.dart';
import 'package:hxdj/common/my_common.dart';
import 'package:hxdj/common/my_constant.dart';
import 'package:hxdj/common/utils/my_cache_util.dart';
import 'package:hxdj/message/rongcloud/rc_engine_manager.dart';

class SafeAccountViewModel extends BaseViewModel {
  // 获取当前缓存的大小
  String cacheSize = "";

  Map<String, dynamic> prams = {
    "userId": 1,
  };

  //退出登录
  Future<void> logout() async {
    bool isSuccess = await RCEngineManager().disconnectIM();
    EasyLoading.showToast(isSuccess ? "成功退出" : "退出失败");
    CommonPlugin.sharedPreferences!.remove(MyConstant.userInfo);
    CommonPlugin.sharedPreferences!.remove(MyConstant.token);

    
  }

  //获取缓存大小
  formatSize() async {
    cacheSize = await MyCacheUtil.formatSize();
    notifyListeners();
  }

  //清除缓存
  clearCache() async {
    await MyCacheUtil.clear();
    EasyLoading.showToast("清除成功");
    formatSize();
  }
}
